/************************************************************************************
* PlaylistWidget.h                                                                  *
*                                                                                   *
* Copyright (C) 2011 Varuna L Amachi                                                *
*                                                                                   *
* This program is free software; you can redistribute it and/or modify              *
* it under the terms of the GNU General Public License as published by              *
* the Free Software Foundation; either version 2 of the License, or any             *
* later version.                                                                    *
*                                                                                   *
* This program is distributed in the hope that it will be useful, but               *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY        *
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for       *
* more details. You should have received a copy of the GNU General Public           *
* License along with this program; if not, write to the Free Software Foundation,   *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                       *
*                                                                                   *
*************************************************************************************/

#ifndef PLAYLISTWIDGET_H
#define PLAYLISTWIDGET_H

#define JOB_CODE_APPEND             0
#define JOB_CODE_INSERT             1
#define JOB_CODE_INSERT_AS_CURRENT  2

#include <QWidget>
#include <phonon/MediaObject>
//#include <QTableView>
#include <QTreeView>
#include <QToolBar>
#include <QLabel>
#include <QProgressBar>


#include "PlaylistModel.h"
#include "common/FileSystemMediaLoader.h"
#include "common/CommonTypes.h"


class PlaylistWidget : public QWidget
{
    Q_OBJECT

    enum CurrentAction {
        ACTION_NONE,
        ACTION_INSERT_AS_CURRENT,
        ACTION_INSERT,
        ACTION_APPEND
    };

    CurrentAction m_action;
    PlaylistModel* m_playlist;
    LoopType m_loopType;
    FileSystemMediaLoader* m_loader;

    QToolBar* m_toolBar;
//    QTableView* m_tableView;
    QTreeView *m_view;
    QProgressBar* m_progress;
    QLabel* m_status;

    QAction* m_removeAction;
    QAction* m_removeAllAction;
    QAction* m_addFolderAction;
    QAction* m_addFilesAction;
    QAction* m_randomize;
    QAction* m_loopAction;
    QAction* m_moveUp;
    QAction* m_moveDown;

    void setupUi();
    void setupToolbar();
    void selectRow(int index);

private slots:
    void clearPlaylist();
    void randomValueChanged();
    void loopValueChanged();
    void indexChanged(MediaItem* dummy, int index);
    void setActionValidity();
    void moveUp();
    void moveDown();
    void setStatus(QString text);
    void clearStatus();
    void setCurrentAction(PlaylistWidget::CurrentAction action);

public:
    explicit PlaylistWidget(QWidget *parent = 0);
    PlaylistModel   *model();
    QTreeView      *view();
    void dragEnterEvent(QDragEnterEvent * event);
    void dropEvent(QDropEvent *event);
    void contextMenuEvent(QContextMenuEvent *event);

public slots:
    void addUrls(QList<QUrl> urls);
    void addFolder();
    void addFiles();
    void insertFile();
    void removeItems();
    void itemLoaded(MediaItem* item);
    void loadingStarted(int numFilesToLoad);
    void loadingFinished();
};

#endif // PLAYLISTWIDGET_H
